import request from '../../../../../public/js/common/api/api.js';
const SaleUrl = Utils.CurDomain.SaleUrl
const SubDataUrl = Utils.CurDomain.SubDataUrl;
const BaseCfgUrl = Utils.CurDomain.BaseCfgUrl;
const AccountUrl = Utils.CurDomain.AccountUrl;
const SysPlfUrl = Utils.CurDomain.SysPlfUrl;
const PigUrl = Utils.CurDomain.PigUrl;

const configuration = {
    contentType: 'application/json',
    dataType: 'json',
    async: true,
    dataFilter(data, type) {
        return data;
    }
}

/**
 * @file 销售出库单
 */
export default class DeliverApi {
    // 查询销售出库单H5列表
    static queryDeliverList(data) {
        return request.post(`${SaleUrl}/deliverbills/plist`, data);
    }

    // 新增
    static addDeliverList(data) {
        return request.post(`${SaleUrl}/deliverbills`, data);
    }

    // 编辑
    static upDeliverList(id, data) {
        return request.put(`${SaleUrl}/deliverbills/${id}`, data);
    }

    // 删除
    static delDeliver(id) {
        return request.delete(`${SaleUrl}/deliverbills/${id}`);
    }

    // 提交
    static putSubmitDeliver(id) {
        return request.put(`${SaleUrl}/deliverbills/submit/${id}`);
    }

    // 反提交
    static putResubmitDeliver(id) {
        return request.put(`${SaleUrl}/deliverbills/resubmit/${id}`);
    }

    // 审核
    static putAuditDeliver(id) {
        return request.put(`${SaleUrl}/deliverbills/audit/${id}`);
    }

    // 反审核
    static putReauditDeliver(id) {
        return request.put(`${SaleUrl}/deliverbills/reaudit/${id}`);
    }

    // 详情
    static getDeliverinfo(id) {
        return request.get(`${SaleUrl}/deliverbills/${id}`);
    }

    // 查信息询登录用户拥有的组织
    static postUserOrgsList() {
        return request.get(`${AccountUrl}/accounts/orgs`);
    }

    static getOrgsListType() {
        return request.get(`${SysPlfUrl}/yyorgunits/by/q/sale`);
    }

    // 获取农场
    static queryDepList(upoid, aotype, taginfo) {
        return request.get(`${SysPlfUrl}/yyorgunits/by/q?upoid=${upoid}&aotype=${aotype}&taginfo=${taginfo}`);
    }

    // 获取物料
    static getMaterialList(id) {
        return request.get(`${Utils.CurDomain.MasterDataUrl}/yymaterials/q`);
    }

    /**
     * 获取行政区划信息
     * @param {*} id 
     * @returns 
     */
    static getDistricts() {
        return request.get(`${SubDataUrl}/districts`);
    }

    /**
     * 销售出库单生成销售订单
     * @param ids
     * @returns 
     */
    static generateDeliverBills(data) {
        return request.post(`${SaleUrl}/deliverbills/generate`, data, true, configuration);
    }

    /**
     * 获取养殖场
     * @param {*} id 
     * @returns 
     */
    static getFarms(id) {
        return request.get(`${BaseCfgUrl}/farms/o/${id}`);
    }

    // 查询用户信息
    static queryUserName(sid) {
        return request.get(`${Utils.CurDomain.WeiXinUrl}/wxauths/cur?sid=${sid}`);
    }


    /**
     * 详情 销售订单
     * @param data
     * @returns 
     */
    static getDetailsSaleOrder(id) {
        return request.get(`${SaleUrl}/orderbills/${id}`);
    }

    /**
     * 根据养殖批次获取猪只耳号
     * @param data
     * @returns 
     */
    static postPigdocs(data) {
        return request.post(`${PigUrl}/pigdocs/batch/list`, data);
    }
    /**
    * 获取SAP 所有物料
    * @returns
    */
    static postMaterial() {
        return request.get(`${Utils.CurDomain.MasterDataUrl}/yymaterials/q?MGroupId=SAP-1&PageSize=100000&PageIndex=0`)
    }
    /**
    *获取参数设置的值
    * @param {*} data
    * @returns 
    */
    static getPrmtSettings(id) {
        return request.get(`${Utils.CurDomain.SubDataUrl}/prmtsettings/${id}/value`);
    }
}